﻿var currentPage = 1; // 当前页
var pageSize = 50; // 每页显示多少条
var pageall = 0; // 总页数
var total = 0; // 总记录数

// 读取列表
$(function() {
    dataBind();

});

// 加载数据
function dataBind() {
    // 1最新盘源 2我的收藏盘 3我的盘源 4笋盘查询
    var typeid = LexunJS.GetQueryString("typeid");
    if (typeid > 0) {
        typeHousing(typeid);
    }
    else {
        showList(currentPage);
    }
}

// 条件查询资源列表
function showList(currentPage) {
    var usage = LexunJS.GetQueryString("usage");                // 用途 1住宅 2商铺 3写字楼 4商住 5仓库 6厂房 7地皮 8项目盘 9其他* 10民房

    if ($("#rbUsageType1").length > 0) {
        if (document.getElementById("rbUsageType1").checked == true)
            usage = "1,4";
    }
    if ($("#rbUsageType2").length > 0) {
        if (document.getElementById("rbUsageType2").checked == true)
            usage = "3,4";
    }
    if ($("#rbUsageType3").length > 0) {
        if (document.getElementById("rbUsageType3").checked == true)
            usage = "2";
    }
    if ($("#rbUsageType4").length > 0) {
        if (document.getElementById("rbUsageType4").checked == true)
            usage = "6";
    }
    if ($("#rbUsageType5").length > 0) {
        if (document.getElementById("rbUsageType5").checked == true)
            usage = "10";
    }

    var name = LexunJS.GetQueryString("name");                  // 楼盘名称
    var buildlist = LexunJS.GetQueryString("buildlist");        // 栋阁ID列表
    var buildlevel = LexunJS.GetQueryString("buildlevel");      // 栋阁所属层级列表  

    var room = LexunJS.GetQueryString("room");                  // 房
    var room1 = LexunJS.GetQueryString("room1");                  // 房
    var hall = LexunJS.GetQueryString("hall");                  // 厅
    var acreage1 = LexunJS.GetQueryString("acreage1");          // 面积
    var acreage2 = LexunJS.GetQueryString("acreage2");          // 面积
    var did = LexunJS.GetQueryString("did");                    // 城区
    var aid = LexunJS.GetQueryString("aid");                    // 片区
    var status = LexunJS.GetQueryString("status");              // 状态
    var tradetype = LexunJS.GetQueryString("tradetype");        // 交易 1出售 2出租 3租售
    var price1 = LexunJS.GetQueryString("price1");              // 租售价
    var price2 = LexunJS.GetQueryString("price2");              // 租售价

    var hasKey = LexunJS.GetQueryString("hasKey");              // 0没钥匙 1有
    var isOnly = LexunJS.GetQueryString("isOnly");              // 0非独家 1独家
    var isCty = LexunJS.GetQueryString("isCty");                //是否反签 1反签
    var hasPhoto = LexunJS.GetQueryString("hasPhoto");          // 0无图片 1有图    
    var pocStatus = LexunJS.GetQueryString("pocStatus");        // 0无红本 1有红本
    var mark2 = LexunJS.GetQueryString("mark2");                // 0无满5年免税 1有满5年免税

    // 高级查询条件
    var id = LexunJS.GetQueryString("id");                      // 序号
    var linkman = LexunJS.GetQueryString("linkman");            // 联系人
    var linktel = LexunJS.GetQueryString("linktel");            // 联系电话
    var unitPrice1 = LexunJS.GetQueryString("unitPrice1");      // 单价1
    var unitPrice2 = LexunJS.GetQueryString("unitPrice2");      // 单价2
    var markUdept = LexunJS.GetQueryString("markUdept");        // 部门
    var adduser = LexunJS.GetQueryString("adduser");            // 开盘人
    var fitment = LexunJS.GetQueryString("fitment");            // 装修
    var houseStyle = LexunJS.GetQueryString("houseStyle");      // 样式
    var direct = LexunJS.GetQueryString("direct");              // 朝向
    var happliances = LexunJS.GetQueryString("happliances");    // 房屋设施
    var type = LexunJS.GetQueryString("type");                  // 类型
    var addDate1 = LexunJS.GetQueryString("addDate1");          // 委托日期
    var addDate2 = LexunJS.GetQueryString("addDate2");          // 委托日期
    var floor1 = LexunJS.GetQueryString("floor1");              // 楼层1
    var floor2 = LexunJS.GetQueryString("floor2");              // 楼层2
    var roomno = LexunJS.GetQueryString("roomno");              // 房间号

    var InfoFrom = LexunJS.GetQueryString("infoFrom");          //来源

    // 排序字段
    var orderByName = $("#hOrderByName").val();
    var orderByType = $("#hOrderByType").val();

    $("#divPage").html(""); // 清空
    $("#divList").html("<img src=\"../images/loading.gif\" />"); // 清空列表 
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=housing_list&page=' + currentPage + '&pagesize=' + pageSize + '&usage=' + usage + '&name=' + escape(name) + '&buildlist=' + escape(buildlist) + '&buildlevel=' + escape(buildlevel)
                    + '&room=' + room + '&room1=' + room1 + '&hall=' + hall
                    + '&acreage1=' + acreage1 + '&acreage2=' + acreage2 + '&did=' + did + '&aid=' + aid + '&status=' + status + '&tradetype=' + tradetype
                    + '&price1=' + price1 + '&price2=' + price2 + '&hasKey=' + hasKey + '&isOnly=' + isOnly + '&hasPhoto=' + hasPhoto + '&pocStatus=' + pocStatus + '&mark2=' + mark2
                    + '&id=' + id + '&linkman=' + linkman + '&linktel=' + linktel + '&unitPrice1=' + unitPrice1 + '&unitPrice2=' + unitPrice2
                    + '&markUdept=' + markUdept + '&adduser=' + adduser + '&fitment=' + fitment + '&houseStyle=' + houseStyle + '&direct=' + direct
                    + '&happliances=' + happliances + '&addDate1=' + addDate1 + '&addDate2=' + addDate2 + '&type=' + type + '&floor1=' + floor1 + '&floor2=' + floor2
                    + '&roomno=' + roomno
                    + '&orderByName=' + orderByName + '&orderByType=' + orderByType+'&isCty='+isCty+'&infoFrom='+InfoFrom,
        timeout: '20000',
        error: function() {
            alert("系统繁忙,请稍候后试！");
        }, success: function(json) {
            listCallBack(json);
        }
    });
}

// typeid 1最新盘源 2我的收藏盘 3我的盘源 4笋盘查询
function typeHousing(typeid) {
    $("#hTypeID").val(typeid);

    if (typeid == 1) {
        $("#sTitle").text("最新盘源");
        showListType(1);
    }
    else if (typeid == 2) {
        window.location.href = "../PM/HousingFavorite.aspx?typeid=2";
    }
    else if (typeid == 3) {
        $("#sTitle").text("我的盘源");
        showListType(1);
    }
    else if (typeid == 4) {
        self.parent.addTab(' 笋盘查询', "../PM/HousingEveryday.aspx?type=1", 'icon-nav');
    }
    else if (typeid == 5) {
        $("#sTitle").text("待过期盘");
        showListType(1);
    }
}

function showListType(currentPage) {
    var typeid = $("#hTypeID").val();   // 1最新盘源 2我的收藏盘 3我的盘源 4笋盘查询

    var usage = LexunJS.GetQueryString("usage");                // 用途 1住宅 2商铺 3写字楼 4商住 5仓库 6厂房 7地皮 8项目盘 9其他* 10民房


    if ($("#rbUsageType1").length > 0) {
        if (document.getElementById("rbUsageType1").checked == true)
            usage = "1,4";
    }
    if ($("#rbUsageType2").length > 0) {
        if (document.getElementById("rbUsageType2").checked == true)
            usage = "3,4";
    }
    if ($("#rbUsageType3").length > 0) {
        if (document.getElementById("rbUsageType3").checked == true)
            usage = "2";
    }
    if ($("#rbUsageType4").length > 0) {
        if (document.getElementById("rbUsageType4").checked == true)
            usage = "6";
    }
    if ($("#rbUsageType5").length > 0) {
        if (document.getElementById("rbUsageType5").checked == true)
            usage = "10";
    }

    var name = LexunJS.GetQueryString("name");                  // 楼盘名称
    var room = LexunJS.GetQueryString("room");                  // 房
    var hall = LexunJS.GetQueryString("hall");                  // 厅
    var acreage1 = LexunJS.GetQueryString("acreage1");          // 面积
    var acreage2 = LexunJS.GetQueryString("acreage2");          // 面积
    var did = LexunJS.GetQueryString("did");                    // 城区
    var aid = LexunJS.GetQueryString("aid");                    // 片区
    var status = LexunJS.GetQueryString("status");              // 状态
    var tradetype = LexunJS.GetQueryString("tradetype");        // 交易 1出售 2出租 3租售
    var price1 = LexunJS.GetQueryString("price1");              // 租售价
    var price2 = LexunJS.GetQueryString("price2");              // 租售价

    var hasKey = LexunJS.GetQueryString("hasKey");              // 0没钥匙 1有
    var isOnly = LexunJS.GetQueryString("isOnly");              // 0非独家 1独家
    var hasPhoto = LexunJS.GetQueryString("hasPhoto");          // 0无图片 1有图
    var pocStatus = LexunJS.GetQueryString("pocStatus");        // 0无红本 1有红本
    var mark2 = LexunJS.GetQueryString("mark2");                // 0无满5年免税 1有满5年免税

    // 高级查询条件
    var id = LexunJS.GetQueryString("id");                      // 序号
    var linkman = LexunJS.GetQueryString("linkman");            // 联系人
    var linktel = LexunJS.GetQueryString("linktel");            // 联系电话
    var unitPrice1 = LexunJS.GetQueryString("unitPrice1");      // 单价1
    var unitPrice2 = LexunJS.GetQueryString("unitPrice2");      // 单价2
    var markUdept = LexunJS.GetQueryString("markUdept");        // 部门
    var adduser = LexunJS.GetQueryString("adduser");            // 开盘人
    var fitment = LexunJS.GetQueryString("fitment");            // 装修
    var houseStyle = LexunJS.GetQueryString("houseStyle");      // 样式
    var direct = LexunJS.GetQueryString("direct");              // 朝向
    var happliances = LexunJS.GetQueryString("happliances");    // 房屋设施
    var type = LexunJS.GetQueryString("type");                  // 类型
    var addDate1 = LexunJS.GetQueryString("addDate1");          // 委托日期
    var addDate2 = LexunJS.GetQueryString("addDate2");          // 委托日期
    var floor1 = LexunJS.GetQueryString("floor1");              // 楼层1
    var floor2 = LexunJS.GetQueryString("floor2");              // 楼层2
    var roomno = LexunJS.GetQueryString("roomno");             // 房间号

    // 排序字段
    var orderByName = $("#hOrderByName").val();
    var orderByType = $("#hOrderByType").val();

    $("#divPage").html(""); // 清空
    $("#divList").html("<img src=\"../images/loading.gif\" />"); // 清空列表 
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=housingtype_list&page=' + currentPage + '&pagesize=' + pageSize + '&typeid=' + typeid
                    + '&usage=' + usage + '&name=' + name + '&room=' + room + '&hall=' + hall
                    + '&acreage1=' + acreage1 + '&acreage2=' + acreage2 + '&did=' + did + '&aid=' + aid + '&status=' + status + '&tradetype=' + tradetype
                    + '&price1=' + price1 + '&price2=' + price2 + '&hasKey=' + hasKey + '&isOnly=' + isOnly + '&hasPhoto=' + hasPhoto + '&pocStatus=' + pocStatus + '&mark2=' + mark2
                    + '&id=' + id + '&linkman=' + linkman + '&linktel=' + linktel + '&unitPrice1=' + unitPrice1 + '&unitPrice2=' + unitPrice2
                    + '&markUdept=' + markUdept + '&adduser=' + adduser + '&fitment=' + fitment + '&houseStyle=' + houseStyle + '&direct=' + direct
                    + '&happliances=' + happliances + '&addDate1=' + addDate1 + '&addDate2=' + addDate2 + '&type=' + type + '&floor1=' + floor1 + '&floor2=' + floor2
                    + '&roomno=' + roomno
                    + '&orderByName=' + orderByName + '&orderByType=' + orderByType,
        timeout: '20000',
        error: function() {
            alert("系统繁忙,请稍候后试！");
        }, success: function(json) {
            listCallBack(json, usage);
        }
    });
}

/*
功能: 将返回的json数据进行排版
json: json数据        
*/
function listCallBack(response, usage) {
    var json = eval("(" + response + ")");
    var record = json.record;

    if (record == null || record.length == 0) {
        $("#divList").html("<font color='red'>&nbsp;系统内暂无您查询的信息!</font>");
        return;
    }

    var page = json.page;

    currentPage = page.currentpage;
    pageall = parseInt(page.pageall);
    total = page.total;
    var typeid = $("#hTypeID").val();               // 1最新盘源 2我的收藏盘 3我的盘源 4笋盘查询
    var isUsage = $("#hIsUsage").val();             // 0表示登录者为住宅业务员 1表示登录者为商铺业务员

    var arr = [];
    arr.push("<table id='tableList' border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
    arr.push("<tr class='fixHeaderStyle'>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    if (typeid != 2)
        arr.push("<input type=\"checkbox\" name=\"checkboxAll\" id=\"checkboxAll\"  onclick=\"cbSelectAll()\" />");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("状态");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('ename')\" >楼盘</a>");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('buildname')\" >栋阁</a>");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('mark1')\" >楼层</a>");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('roomno')\" >房间号</a>");
    arr.push("</td>");

    // 分商铺、住宅
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");

    if (isUsage == 0)
        arr.push("<a href=\"javascript:searchOrderBy('room')\" >户型</a>");
    else
        arr.push("<a href=\"javascript:searchOrderBy('tenant')\" >现租客</a>");
    arr.push("</td>");

    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('acreage')\" >面积</a>");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('leaseprice')\" >租售价</a>");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('unitprice')\" >单价</a>");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('remark')\" >备注</a>");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('keyno')\" >钥匙编号</a>");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('fitment')\" >装修</a>");
    arr.push("</td>");
    
    if (isUsage == 0) {
        arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
        arr.push("<a href=\"javascript:searchOrderBy('pocstatus')\" >红本在手</a>");
        arr.push("</td>");
        arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
        arr.push("<a href=\"javascript:searchOrderBy('mark2')\" >满五年</a>");
        arr.push("</td>");
    }   

    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    if (isUsage != 0)
        //arr.push("<a href=\"javascript:searchOrderBy('fitment')\" >装修</a>");
    //else
        arr.push("<a href=\"javascript:searchOrderBy('assignmentfee')\" >转让费</a>");

    arr.push("</td>");

    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('[use]')\" >用途</a>");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('area')\" >片区</a>");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('markdate')\" >委托日期</a>");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('uddate')\" >上次跟进</a>");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('markuser')\" >开盘人</a>");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('markudept')\" >开盘人部门</a>");
    arr.push("</td>");
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('tradetype')\" >交易类型</a>");
    arr.push("</td>");
    
    arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<a href=\"javascript:searchOrderBy('')\" >盘源编号</a>");
    arr.push("</td>");

    // 权限判断
    var hCompetencesIsEdit = $("#hCompetencesIsEdit").val();    // 0不允许修改 1允许修改
    if (hCompetencesIsEdit == 1) {
        arr.push("<td  height='25' bgcolor='d3eaef' class='STYLE10'>");
        arr.push("基本操作");
        arr.push("</td>");
    }
 
    arr.push("</tr>");

    var id_list = "";   // 保存查询出盘源的ID 如 1211,1212,1213...
    var recordLength = record.length;
    for (var i = 0; i < recordLength; i++) {
        id_list += record[i].id;
        if (i < recordLength - 1)
            id_list += ",";

        if (i % 2 == 0)
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#FFFFFF' style='cursor: pointer;' onclick=\"selectedTr('" + record[i].id + "')\" >");
        else
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#EEEDED' style='cursor: pointer;' onclick=\"selectedTr('" + record[i].id + "')\" >");

        arr.push("<td  height='25' style='text-align: left;' class='STYLE6'>");
        if (typeid != 2)
            arr.push("<input type='checkbox' name='checkbox_" + record[i].id + "' id='" + record[i].id + "' onclick=\"cbSelect(this, " + record[i].id + ")\" />");

        if (record[i].haskey > 0)
            arr.push("<img src=\"../images/u485.gif\" title='钥匙人:" + record[i].keepkey + " 编号:" + record[i].keyno + "' />");
        if (record[i].isonly > 0)
            arr.push("<img src=\"../images/u483.gif\" title='独家盘' />");
        if (record[i].hasphoto > 0)
            arr.push("<img src=\"../images/xtgl.gif\" title='该盘有图片' />");
        if (record[i].ctycont > 0)
            arr.push("<img src=\"../images/u481.gif\" title='被反签' />");
        if (record[i].protected > 0)
            arr.push("<img src=\"../images/062.gif\" title='已封盘' />");
        if (record[i].recommend > 0)
            arr.push("<img src=\"../images/mbi_005.gif\" title='被推荐' />");
        arr.push("</td>");

        arr.push("<td  height='25' class='STYLE6'>");
        if (record[i].status == 1)
            arr.push("当前");
        else if (record[i].status == 2)
            arr.push("资料");
        else if (record[i].status == 3)
            arr.push("无效");
        arr.push("</td>");
        
        arr.push("<td  height='25' style='text-align:left;' class='STYLE6'>");
        if (typeid == 2)
            arr.push("<a href='#' onclick=\"openDetail('" + record[i].housingid + "')\">" + record[i].ename + "</a>");
        else
            arr.push("<a href='#' onclick=\"openDetail('" + record[i].id + "')\">" + record[i].ename + "</a>");
        if (record[i].estateothername != "")
            arr.push("(" + record[i].estateothername + ")");

        arr.push("</td>");
        arr.push("<td  height='25' style='text-align:left;' class='STYLE6'>");
        arr.push(record[i].buildname);
        if (record[i].othername != "")
            arr.push("(" + record[i].othername + ")");
        arr.push("</td>");
        arr.push("<td  height='25' class='STYLE6'>");
        arr.push(record[i].mark1);
        arr.push("</td>");
        arr.push("<td  height='25' class='STYLE6'>");
        arr.push(record[i].roomno);
        arr.push("</td>");
        arr.push("<td  height='25' class='STYLE6'>");
        if (isUsage == 0)
            arr.push(record[i].room + "-" + record[i].hall + "-" + record[i].restroom + "-" + record[i].balcony);
        else
            arr.push(record[i].tenant);
        arr.push("</td>");
        arr.push("<td  height='25' class='STYLE6'>");
        arr.push(parseInt(record[i].acreage));
        arr.push("</td>");
        arr.push("<td  height='25' class='STYLE6'>");
        if (record[i].tradetype == 1)
            arr.push(parseInt(record[i].totalprice) + "万");
        else
            arr.push(parseInt(record[i].leaseprice));
        arr.push("</td>");
        arr.push("<td  height='25' class='STYLE6'>");
        arr.push(parseInt(record[i].unitprice));
        arr.push("</td>");
        arr.push("<td  height='25' class='STYLE6' title='" + record[i].remark + "'>");
        if (record[i].remark.length >= 8)
            arr.push(record[i].remark.substring(0, 8) + "...");
        else
            arr.push(record[i].remark);
        arr.push("</td>");
        arr.push("<td height='25' class='STYLE6'>");
        arr.push(record[i].keyno);
        arr.push("</td>");

        arr.push("<td height='25' class='STYLE6'>");
        arr.push(record[i].fitment);
        arr.push("</td>");

        if (isUsage == 0) {
            arr.push("<td height='25' class='STYLE6'>");            
            if (record[i].pocstatus == '红本')
                arr.push("是");
            else
                arr.push("否");
            arr.push("</td>");
            arr.push("<td height='25' class='STYLE6'>");
            if (record[i].mark2 == '满5年免税')
                arr.push("是");
            else
                arr.push("否");
            arr.push("</td>");
        }   
        
        arr.push("<td  height='25' class='STYLE6'>");
        if (isUsage != 0)
            //arr.push(record[i].fitment);
        //else
            arr.push(record[i].assignmentfee);
        arr.push("</td>");
        arr.push("<td height='25' class='STYLE6'>");

        arr.push(LexunJS.GetUsageNameById(record[i].use));
        arr.push("</td>");
        arr.push("<td  height='25' class='STYLE6'>");
        arr.push(record[i].area);
        arr.push("</td>");
        arr.push("<td  height='25' class='STYLE6'>");
        arr.push(record[i].markdate);
        arr.push("</td>");
        arr.push("<td  height='25' class='STYLE6'>");
        arr.push(record[i].uddate);
        arr.push("</td>");
        arr.push("<td  height='25' class='STYLE6'>");
        arr.push(record[i].markuser);
        arr.push("</td>");
        arr.push("<td  height='25' class='STYLE6'>");
        arr.push(record[i].markudept);
        arr.push("</td>");

        arr.push("<td  height='25' class='STYLE6'>");
        if (record[i].tradetype == 1)
            arr.push("出售");
        else if (record[i].tradetype == 2)
            arr.push("出租");
        arr.push("</td>");        

        arr.push("<td  height='25' class='STYLE6'>");
        if (typeid == 2)
            arr.push(record[i].housingid);
        else
            arr.push(record[i].id);
        arr.push("</td>");

        // 权限判断                
        if (hCompetencesIsEdit == 1) {
            arr.push("<td  height='25'  class='STYLE6'>");
            if (typeid == 2)
                arr.push("<input id=\"Button1\" type=\"button\" value=\"取消收藏\" class=\"button_bak\" onclick=\"return favorite(" + record[i].housingid + ", 0)\" />");
            else if (typeid == 4)
                arr.push("<input id=\"Button2\" type=\"button\" value=\"取消推荐\" class=\"button_bak\" onclick=\"return recommend(" + record[i].id + ", 0)\" />");
            else 
                arr.push("<a href='javascript:detail(" + record[i].id + ")'>修改</a>");
            
            arr.push("</td>");
        }

      
        
        arr.push("</tr>");
    }
    arr.push("</table>");
    $("#divList").html(arr.join('')); // 显示列表
    $("#divPage").html(""); // 清空

    var pageHtml = LexunJS.showPage(currentPage, pageall, "showList"); // 分页
    if (typeid > 0)
        pageHtml = LexunJS.showPage(currentPage, pageall, "showListType"); // 分页
    $("#divPage").html(pageHtml);

    $("#hID_List").val(id_list);
}

// 响应键盘查询
function responseEnter(e) {
    var key = window.event ? e.keyCode : e.which;
    if (key == 13)
        search();
}

// 条件查询
function search() {

    $("#divList").html(""); // 清空列表
    $("#divPage").html(""); // 清空分页    

    var typeid = LexunJS.GetQueryString("typeid");
    if (typeid > 0) {
        typeHousing(typeid);
    }
    else {
        showList(1);
    }
}

// 按字段排序
function searchOrderBy(orderName) {
    $("#divList").html("");     // 清空列表
    $("#divPage").html("");     // 清空分页

    $("#hOrderByName").val(orderName);     // 保存排序字段
    var orderByType = $("#hOrderByType").val();
    if (orderByType == "asc")
        $("#hOrderByType").val("desc");
    else
        $("#hOrderByType").val("asc");

    var typeid = LexunJS.GetQueryString("typeid");
    if (typeid > 0) {
        typeHousing(typeid);
    }
    else {
        showList(1);
    }
}

// 打开高级查询框
function iAdvancedSearch_onclick() {
    var obj = document.getElementById("divAdvancedSearch");

    $("#divAdvancedSearch").toggle();
}

// 单选
function cbSelect(obj, objvalue) {
    if (obj.checked) {
        LexunJS.addOrCutData(1, "hID", objvalue);

    }
    else {
        LexunJS.addOrCutData(0, "hID", objvalue);
    }
}

// 全选
function cbSelectAll() {
    document.getElementById("hID").value = "";

    var cbAll = document.getElementById("checkboxAll");
    var checkList = document.getElementsByTagName("input");

    if (cbAll.checked) {
        for (var i = 0; i < checkList.length; i++) {
            if (checkList[i].type == "checkbox" && checkList[i].id > 0) {
                checkList[i].checked = true;
                if (parseInt(checkList[i].id) > 0) LexunJS.addOrCutData(1, "hID", checkList[i].id);
            }
        }
    }
    else {
        for (var i = 0; i < checkList.length; i++) {
            if (checkList[i].type == "checkbox" && checkList[i].id > 0) {
                checkList[i].checked = false;
                if (parseInt(checkList[i].id) > 0) LexunJS.addOrCutData(0, "hID", checkList[i].id);
            }
        }
    }
}

// 选中某行
function selectedTr(id) {
    $("tr").removeClass("selected");
    $("#tr_" + id).addClass("selected");
}

// 查看详情
function openDetail(id) {
    $("tr").removeClass("selected");
    $("#tr_" + id).addClass("selected");

    var id_list = $("#hID_List").val();
    var url = "../PM/HousingDetail.aspx?id=" + escape(id.tostring()) + "&id_list=" + escape(id_list);
    var style = "left = 50, screenX = 0, top = 50, screenY = 0, resizable = yes, scrollbars = yes,width=750px, height=600px,Toolbar=no,Location=no,Direction=no,Resizeable=no";

   window.open(url, '', style);
       //self.parent.closeTab('盘源详情[' + id + ']');
      //self.parent.addTab('盘源详情[' + id + ']', url, 'icon-nav');

}

// 修改
function detail(id) {
    if (id <= 0) {
        var IDList = document.getElementById("hID").value;
        var idlist = IDList.split('|');
        var idleng = idlist.length - 1;
        id = idlist[0];
        if (idleng > 1) {
            alert("只能选择一行！");
            return false;
        }
        if (id == "") {
            alert("请先选择您要修改的盘源！");
            return false;
        }

    }
    
    document.getElementById("hID").value = "";

    var url = "../PM/EstateUpdate.aspx?id=" + id;
    self.parent.closeTab('修改盘源');
    self.parent.addTab('修改盘源', url, 'icon-nav');

}

function detail1(id) {
    if (id <= 0) {
        var IDList = document.getElementById("hID").value;
        var idlist = IDList.split('|');
        var idleng = idlist.length - 1;
        id = idlist[0];
        if (idleng > 1) {
            alert("只能选择一行！");
            return false;
        }
        if (id == "") {
            alert("请先选择您要修改的盘源！");
            return false;
        }

    }

    document.getElementById("hID").value = "";

    var url = "../PM/EstateUpdate.aspx?id=" + id;
    self.parent.closeTab('修改盘源');
    self.parent.addTab('修改盘源', url, 'icon-nav');

    return false;

}



// 删除
function del() {
    var IDList = document.getElementById("hID").value;
    if (IDList == "") {
        alert("请先选择您要删除的行！");
        return false;
    }

    if (confirm("您确定要删除该行，请谨慎操作！")) {
        // ajax删除                   
        $.ajax({
            type: 'POST',
            url: '../Handler/HandlerHousing.ashx',
            data: 'act=housing_del&id=' + IDList,
            timeout: '10000',
            error: function() {
                alert("删除失败！");
            }, success: function(outmsg) {
                alert(outmsg);
                showList(currentPage);
                document.getElementById("hID").value = "";
            }
        });
    }

    return false;
}

// 笋盘推荐 0取消推荐 1推荐
function recommend(id, isrecommend) {
    var outmsg = "推荐";
    var IDList = document.getElementById("hID").value;

    if (isrecommend == 0) {
        outmsg = "取消推荐";
    } else {
        if (IDList == "") {
            alert("请先选择您要" + outmsg + "的盘源！");
            return false;
        }
    }

    if (confirm("您确定要" + outmsg + "该盘源，请谨慎操作！")) {
        $.ajax({
            type: 'POST',
            url: '../Handler/HandlerHousing.ashx',
            data: 'act=housing_recommend&idlist=' + IDList + '&id=' + id + '&isrecommend=' + isrecommend,
            timeout: '10000',
            error: function() {
                alert(outmsg + "失败！");
            }, success: function(outmsg) {
                alert(outmsg);

                if (isrecommend == 0)
                    showListType(currentPage);
                else
                    showList(currentPage);

                document.getElementById("hID").value = "";
            }
        });
    }

    return false;
}

// 收藏盘 0取消收藏 1收藏
function favorite(id, isfavorite) {
    var outmsg = "收藏";
    var IDList = document.getElementById("hID").value;

    if (isfavorite == 0) {
        outmsg = "取消收藏";
    } else {
        if (IDList == "") {
            alert("请先选择您要" + outmsg + "的盘源！");
            return false;
        }
    }

    if (confirm("您确定要" + outmsg + "该盘源，请谨慎操作！")) {
        $.ajax({
            type: 'POST',
            url: '../Handler/HandlerHousing.ashx',
            data: 'act=housing_favorite&idlist=' + IDList + '&id=' + id + '&isfavorite=' + isfavorite,
            timeout: '10000',
            error: function() {
                alert(outmsg + "失败！");
            }, success: function(outmsg) {
                alert(outmsg);

                if (isfavorite == 0)
                    showListType(currentPage);
                else
                    showList(currentPage);

                document.getElementById("hID").value = "";
            }
        });
    }

    return false;
}

// 每日一盘
function everyday() {
    var IDList = document.getElementById("hID").value;
    var idlist = IDList.split('|');
    var idleng = idlist.length - 1;
    var id = idlist[0];

    if (idleng > 1) {
        alert("只能选择一行！");
        return false;
    }

    if (id == "") {
        alert("请先选择您要推荐到每日一盘的盘源！");
        return false;
    }


    if (confirm("您确定要推荐该盘源到每日一盘，请谨慎操作！")) {
        $.ajax({
            type: 'POST',
            url: '../Handler/HandlerHousing.ashx',
            data: 'act=housing_everyday_add&id=' + id,
            timeout: '10000',
            error: function() {
                alert("推荐失败");
            }, success: function(outmsg) {
                alert(outmsg);
                document.getElementById("hID").value = "";
            }
        });
    }

    return false;
}

// 封盘
function lock() {
    var IDList = document.getElementById("hID").value;
    if (IDList == "") {
        alert("请先选择您要封锁的盘源！");
        return false;
    }

    if (confirm("您确定要封锁该盘源，请谨慎操作！")) {
        //        // ajax删除                   
        //        $.ajax({
        //            type: 'POST',
        //            url: '../Handler/HandlerHousing.ashx',
        //            data: 'act=housing_lock&isProtected=1&id=' + IDList,
        //            timeout: '10000',
        //            error: function() {
        //                alert("封盘失败！");
        //            }, success: function(outmsg) {
        //                alert(outmsg);
        //                document.getElementById("hID").value = "";
        //            }
        //        });
        var path = "HousingLockInput.aspx?id=" + IDList;
        var parameter = "转成交盘原因";
        var style = "dialogWidth:500px; dialogHeight:290px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";
        window.showModalDialog(path, parameter, style);
        window.location.reload();
    }

    return false;
}

//弹出窗口 
function ShowDialog() {
    var IDList = document.getElementById("hID").value;
    var idlist = IDList.split('|');
    var idleng = idlist.length - 1;
    var id = idlist[0];
    if (idleng > 1) {
        alert("只能选择一行！");
        return false;
    }
    if (id == "") {
        alert("请先选择您要举报的房源！");
        return false;
    }
    var path = "EstateShowInfo.aspx?hid=" + id + '&deptid=0';
    var parameter = "盘源举报";
    var style = "dialogWidth:538px; dialogHeight:430px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";

    window.showModalDialog(path, parameter, style);


    return false;
}


//弹出窗口 (笋盘推荐)
function ShowDialogListing() {
    var IDList = document.getElementById("hID").value;
    var idlist = IDList.split('|');
    var idleng = idlist.length - 1;
    var id = idlist[0];
    if (idleng > 1) {
        alert("只能选择一行！");
        return false;
    }
    if (id == "") {
        alert("请先选择您要推荐的房源！");
        return false;
    }
    var path = "Listing.aspx?hid=" + id;
    var parameter = "笋盘推荐";
    var style = "dialogWidth:538px; dialogHeight:233px; status:0;scroll:1; help:0; resizable:1;Scrollbars=no,Toolbar=no,Location=no,Direction=no,Resizeable=no";

    window.showModalDialog(path, parameter, style);


    return false;
}


